package com.demo6.demo.core.service;

import com.demo6.demo.core.entity.Student;
import com.demo6.demo.core.entity.StudentExample;
import com.demo6.demo.core.mapper.StudentMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * User: wangy
 * Date: 2020/6/11
 * Description: No Description
 */
@Service("studentService")
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;

    @Override
    public List<Student> studentAll(Student student) {
        int pageNum = student.getPageNumber();
        int pageSize = student.getPageSize();
        StudentExample example = new StudentExample();
        StudentExample.Criteria criteria = example.createCriteria();

        if (student.getSname() != null) {
            criteria.andSnameEqualTo(student.getSname());
        }

        if (student.getAge() != null) {
            criteria.andAgeEqualTo(student.getAge());
        }

        PageHelper.startPage(pageNum, pageSize);
        return studentMapper.selectByExample(example);
    }
}
